package com.koron.css2.clientCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.UserChangePersonBean;
import com.koron.css2.clientCenter.mapper.ChangeUserMapper;
import com.koron.css2.clientCenter.queryBean.UserPersonDetailQueryBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class UserPersonTempLadderNum implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		// TODO Auto-generated method stub
		try {
			MessageBean<PageInfo> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功",
					PageInfo.class);
			ChangeUserMapper mapper = factory.getMapper(ChangeUserMapper.class);
			UserPersonDetailQueryBean bean = JsonUtils.objectToPojo(req.getData(), UserPersonDetailQueryBean.class);
			// 获取用户人口信息
			PageHelper.startPage(bean.getPage(), bean.getPageCount());
			List<UserChangePersonBean> person = mapper.getUserChangePersonById(bean.getUserNo());
			for (UserChangePersonBean userPersonDetailBean : person) {
				if (StringUtils.isNotBlank(userPersonDetailBean.getCertType())) {
					userPersonDetailBean.setCertType(Tools.getDicNameByCodeAndValue(factory, "IDT", userPersonDetailBean.getCertType()));
				}
			}
			info.setData(new PageInfo<>(person));
			return info;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			logger.error("用水人口列表查询失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
